package com.sgb.kjwl.view.ui.fragment.home;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.core.widget.NestedScrollView;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.tabs.TabLayout;
import com.sgb.alimaplibrary.MapLocationTools;
import com.sgb.auction.activity.AuctionHallActivity;
import com.sgb.goods.entity.GoodsItemEntity;
import com.sgb.goods.view.activity.inquiry.NewPurchasesActivity;
import com.sgb.jicai.view.activity.FactoryCentralizedActivity;
import com.sgb.jicai.view.activity.JcMyPriceActivity;
import com.sgb.jicai.view.activity.JiCaiDaTingActivity;
import com.sgb.jicai.view.activity.MyCenterMyJoinActivity;
import com.sgb.jicai.view.activity.XuFangFaQiActivity;
import com.sgb.kjwl.BaseHeightViewPagerFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentBigHome3Binding;
import com.sgb.kjwl.di.home.DaggerHomeFragComponent;
import com.sgb.kjwl.di.home.HomeFragModule;
import com.sgb.kjwl.model.entity.BannerEntity;
import com.sgb.kjwl.model.entity.HomeMenuEntity;
import com.sgb.kjwl.model.entity.home.HomeAdEntity;
import com.sgb.kjwl.model.entity.home.PictureEntity;
import com.sgb.kjwl.model.entity.home.RefreshHomeNoticeEVent;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.NumberConstant;
import com.sgb.kjwl.view.event.CategoryEvent;
import com.sgb.kjwl.view.event.CategoryEvent2;
import com.sgb.kjwl.view.event.ChooseAreaEvent;
import com.sgb.kjwl.view.event.special.QuickEntryEvent;
import com.sgb.kjwl.view.ui.adapter.CommPagerAdapter2;
import com.sgb.knowledgeshare.utils.SharePermissionUtils;
import com.sgb.knowledgeshare.view.activity.HomeShareActivity;
import com.sgb.knowledgeshare.view.activity.ShareRecoedVideoActivity;
import com.swgk.core.event.MenuEvent;
import com.sgb.kjwl.view.ui.activity.enterprise.MakeOverActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.NeedActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalQuoteActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalTeamChangeActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.ServiceTypeActivity;
import com.sgb.kjwl.view.ui.activity.home.HomeCategoryActivity;
import com.sgb.kjwl.view.ui.activity.home.SearchActivity3;
import com.sgb.kjwl.view.ui.activity.house.LeaseHallMapActivity;
import com.sgb.kjwl.view.ui.activity.lease.LeaseHallActivity2;
import com.sgb.kjwl.view.ui.activity.logistics.LogisticsMapActivity;
import com.sgb.kjwl.view.ui.activity.manage.CompanyTradesActivity;
import com.sgb.kjwl.view.ui.activity.manage.EnterpriseAndMapActivity;
import com.sgb.kjwl.view.ui.activity.manage.EnterpriseAndMapActivity3;
import com.sgb.kjwl.view.ui.activity.manage.EpAssestActivity;
import com.sgb.kjwl.view.ui.activity.manage.IPActivity;
import com.sgb.kjwl.view.ui.activity.manage.ManageActivity;
import com.sgb.kjwl.view.ui.activity.manage.SpecialQualificationActivity;
import com.sgb.kjwl.view.ui.activity.manage.TheEnterpriseOfActivity;
import com.sgb.kjwl.view.ui.activity.manage.TradeHonorActivity;
import com.sgb.kjwl.view.ui.activity.material.GoodsAggregateActivity;
import com.sgb.kjwl.view.ui.activity.packers.FigureCheckActivity;
import com.sgb.kjwl.view.ui.activity.packers.FindPackersActivity;
import com.sgb.kjwl.view.ui.activity.packers.LaborServiceAndEmploymentActivity;
import com.sgb.kjwl.view.ui.activity.packers.PackersEmploymentActivity;
import com.sgb.kjwl.view.ui.activity.packers.PackersEngineeringCompanyActivity;
import com.sgb.kjwl.view.ui.activity.packers.PackersEngineeringTenderActivity;
import com.sgb.kjwl.view.ui.activity.packers.PackersFindPeopleActivity;
import com.sgb.kjwl.view.ui.activity.packers.ServicesCompanyActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickBiddingListActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickHallActivity3;
import com.sgb.kjwl.view.ui.activity.pick.PickListActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickMapActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickNoticeActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickWinningNoticeActivity;
import com.sgb.kjwl.view.ui.activity.quotedprice.QuotedPriceActivity;
import com.sgb.kjwl.view.ui.activity.self.authentication.AuthActivity3;
import com.sgb.kjwl.view.ui.activity.self.logistics.PublishCargoActivity;
import com.sgb.kjwl.view.ui.activity.self.mine.IntelligentAttentionActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.CarPublishActivity1;
import com.sgb.kjwl.view.ui.activity.self.publish.DevicePublishActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.GoodsPublishActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.LeaseMachineActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.PackersPublishActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.ChangePasswordActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.activity.supplier3.SupplierActivity4;
import com.sgb.kjwl.view.ui.activity.transport.BiddingTransportHallActivity;
import com.sgb.kjwl.view.ui.activity.transport.DriverLookForGoodsActivity;
import com.sgb.kjwl.view.ui.activity.transport.GoodsCarsActivity;
import com.sgb.kjwl.view.ui.adapter.home.HomeMenuAdapter;
import com.sgb.kjwl.view.ui.adapter.home.HomePictureAdapter;
import com.sgb.kjwl.view.ui.quickentry.QuickEntryClickListener;
import com.sgb.kjwl.view.ui.quickentry.QuickEntryEntity;
import com.sgb.kjwl.view.ui.quickentry.QuickEntryPopWindow;
import com.sgb.kjwl.viewmodel.home.BigHomeFragModel3;
import com.sgb.link.router.PathLogistics;
import com.sgb.link.router.PathMerchant;
import com.sgb.link.router.PathTeam;
import com.sgb.link.utils.SizeUtils;
import com.sgb.member.ui.activity.MemberAuditActivity;
import com.sgb.member.ui.activity.MemberInviteOrApplyActivity;
import com.sgb.member.ui.activity.MemberManageActivity;
import com.sgb.zhaocai.view.demand.activity.DemandForecastActivity;
import com.stx.xhb.androidx.XBanner;
import com.swgk.core.FlowLogUtils;
import com.swgk.core.base.AppFragment;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.HeightViewPager;
import com.swgk.core.dialog.RoundCornerDialog;
import com.swgk.core.event.EventConstant;
import com.swgk.core.mmkvutil.CacheMarker;
import com.swgk.core.mmkvutil.DatalUtils;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.refresh.SuperSwipeRefreshLayout;
import com.swgk.core.util.ACAdminDialogUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.entity.EnterpriseEditEntity;
import com.swgk.core.view.entity.HomeManageMenuEntity;
import com.swgk.core.view.entity.MenuEntity;
import com.swgk.core.view.recyclerview.HorizontalItemDecoration;
import com.swgk.core.view.weiget.BigHomeComparyWidget;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

import static com.sgb.kjwl.utils.NumberConstant.TEAM_CONSTRUCTION;


/**
 * 2020-10月-20日
 * 张家辅
 */
public class BigHomeFragment3 extends AppFragment {
    @Inject
    BigHomeFragModel3 model;
    private FragmentBigHome3Binding binding;
    public static final String KEY_TYPE = "type";
    public static final String MATERIAL = "material";//材料
    public static final String RECRUIT = "recruit";//招标
    public static final String RENT = "rent";//租赁
    public static final String TEAM = "team";//团队
    public static final String LOGISTICS = "logistics";//物流
    public static final String COLLEGE = "college";//知识分享
    public static final String GROUPBUY = "groupbuy";//集采
    public static final String OPERATION = "operation";//企业经营
    public static final String SERVICES = "enterprise";//企业服务
    public static final String MERCHANTS = "investment";//招商引资
    private MapLocationTools mapLocationTools;

    private ArrayList<BigHomeVideoFragment> fragmentVideoList;
    private CommPagerAdapter2 pagerAdapter2;
    private boolean isPersonAuth = false;
    private List<MenuEntity> titleData;
    private List<BannerEntity> bannerList;
    private List<List<Fragment>> bigHomeFragment = new ArrayList<>(); //界面所有模块集合
    private HomePictureAdapter homePictureAdapter;
    private List<MenuEntity> shopmenuList = new ArrayList<>(); //商品分类二级
    private FlowLogUtils flowLogUtils;
    private RequestManager requestManager;
    private boolean isCreate = false;
    private boolean init = true;
    private boolean isVisible;

    private List<MenuEntity<MenuEntity<MenuEntity>>> mMaterialData = new ArrayList<>();
    private ViewStub vsJicai;
    private HeightViewPager vpJicai;
    private TabLayout tlTitleJicai;
    private TextView tvTitleJicai;

    private HomeMenuEntity jicaiHomeMenuEntity;
    private HomeMenuEntity zulinHomeMenuEntity;
    private HomeMenuEntity gongduiHomeMenuEntity;
    private HomeMenuEntity zhaocaiHomeMenuEntity;
    private HomeMenuEntity wuliuHomeMenuEntity;
    private HomeMenuEntity qifuHomeMenuEntity;
    private HomeMenuEntity zhaoshangHomeMenuEntity;
    private HomeMenuEntity qiyeHomeMenuEntity;
    private HomeMenuEntity shangpinHomeMenuEntity;
    private List<MenuEntity> fenxiangList = new ArrayList<>();
    private Disposable subscribe;
    private boolean renderComplete;//页面渲染是否完成
    private boolean isChangeCity;//是否切换城市
    private int i = 0;//标记渲染模块
    private int f = 0;//
    private ViewStub vsZulin;
    private HeightViewPager vpZulin;
    private TabLayout tlTitleZulin;
    private TextView tvTitleZulin;

    private ViewStub vsShangpin;
    private HeightViewPager vpShangpin;
    private TabLayout tlTitleShangpin;
    private TextView tvTitleShangpin;

    private ViewStub vsGongdui;
    private HeightViewPager vpGongdui;
    private TabLayout tlTitleGongdui;
    private TextView tvTitleGongdui;

    private ViewStub vsZhaocai;
    private HeightViewPager vpZhaocai;
    private TabLayout tlTitleZhaocai;
    private TextView tvTitleZhaocai;

    private ViewStub vsWuliu;
    private HeightViewPager vpWuliu;
    private TabLayout tlTitleWuliu;
    private TextView tvTitleWuliu;

    private ViewStub vsQifu;
    private HeightViewPager vpQifu;
    private TabLayout tlTitleQifu;
    private TextView tvTitleQifu;

    private ViewStub vsZhaoshang;
    private HeightViewPager vpZhaoshang;
    private TabLayout tlTitleZhaoshang;
    private TextView tvTitleZhaoshang;

    private ViewStub vsQiye;
    private HeightViewPager vpQiye;
    private TabLayout tlTitleQiye;
    private TextView tvTitleQiye;

    private ViewStub vsFenxiang;
    private ViewPager vpFenxiang;
    private TabLayout tlTitleFenxiang;
    private TextView tvTitleFenxiang;

    private QuickEntryPopWindow quickEntryPopWindow; //快捷入口弹框



    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        DaggerHomeFragComponent.builder()
                .appComponent(appComponent)
                .homeFragModule(new HomeFragModule(this))
                .build()
                .inject(this);
    }

    public static BigHomeFragment3 newInstance(String type) {
        BigHomeFragment3 fragment = new BigHomeFragment3();
        Bundle bundle = new Bundle();
        bundle.putString(KEY_TYPE, type);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        isVisible = isVisibleToUser;
        //相当于Fragment的onResume
        if (isVisibleToUser) {
            checkModuleFragment();
        }
        if (!isCreate) {
            return;
        }
        if (isVisibleToUser && init) {
            init = false;
            initView();
            init();
        }
    }

    /**
     * 从别的界面切换回来时，检测当前界面数据是否加载完整
     */
    private void checkModuleFragment() {
        if (bigHomeFragment.size() > 0) {
            for (int i = 1; i < bigHomeFragment.size(); i++) {
                if (bigHomeFragment.get(i) != null && bigHomeFragment.get(i).size() != 0) {
                    //得到当前布局中的第一个承载布局
                    Fragment fragment = bigHomeFragment.get(i).get(0);
                    if (fragment != null) {
                        if (fragment instanceof BaseHeightViewPagerFragment) {
                            BaseHeightViewPagerFragment baseHeightViewPagerFragment = (BaseHeightViewPagerFragment) fragment;
                            if (!baseHeightViewPagerFragment.isInitData) {
                                baseHeightViewPagerFragment.lazyLoad();
                            }
                        }
                    }
                }
            }
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isCreate = true;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_big_home3, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (init && isVisible) {
            init = false;
            initView();
            init();
        }
    }

    private void initView() {
        requestManager = Glide.with(this);
        //int screenHeight = SizeUtils.getScreenHeight(getActivity());
        int screenHeight = SizeUtils.dp2px(232);

        //控制置顶按钮的显示隐藏
        binding.scrollview.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                if (scrollY > screenHeight) {
                    binding.imgBackTop.setVisibility(View.VISIBLE);
                } else if (scrollY < screenHeight) {
                    binding.imgBackTop.setVisibility(View.GONE);
                }
            }
        });

        binding.imgBackTop.setOnClickListener(v -> {
            binding.scrollview.smoothScrollTo(0, 0);
            binding.scrollview.scrollTo(0, 0);
        });
        binding.swipeRefresh.setHeaderView(createHeaderView());
        binding.swipeRefresh.setOnPullRefreshListener(new SuperSwipeRefreshLayout.OnPullRefreshListener() {
            @SuppressLint("CheckResult")
            @Override
            public void onRefresh() {
                textView.setText("正在刷新");
                if (renderComplete) {
                    //商品三级分类的数据
                    model.getCategoryModel();
                    //banner数据
                    model.getHomeMenuList(true);
                    //获取首页企业推荐
                    model.getCompanyTitleList("onRefresh");
                    //获取大首页广告banner图集
                    model.getHomeAdData(true);
                    //视频分类
                    model.videoTypeList(true);
                    //各模块总分类数据
                    model.recomandCate(true);
                    //商品突查tab
                    model.getMenuModels("", true);
                }
                Observable.timer(1000, TimeUnit.MILLISECONDS)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(aLong -> {
                            closeRefresh();
                        });
            }

            @Override
            public void onPullDistance(int distance) {
            }

            @Override
            public void onPullEnable(boolean enable) {
                textView.setText(enable ? "释放立即刷新" : "下拉刷新");
            }
        });

        homePictureAdapter = new HomePictureAdapter(getContext(), null);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
        binding.recyclerViewImg.addItemDecoration(new HorizontalItemDecoration(10, getContext(), true));
        binding.recyclerViewImg.setLayoutManager(linearLayoutManager);
        binding.recyclerViewImg.setAdapter(homePictureAdapter);
        homePictureAdapter.setOnItemClick(new AdapterOnItemClick<PictureEntity>() {
            @Override
            public void onItemClick(PictureEntity pictureEntity, int position) {
                homePictureItemClick(pictureEntity.getName());
            }
        });

        binding.ivQuickEntry.setOnClickListener(this);
    }

    private void showShangpinView() {
        if (binding == null) {
            return;
        }
        vsShangpin = binding.vsShangpin.getViewStub();
        if (vsShangpin != null) {
            vsShangpin.inflate();
            LinearLayout inflatedShangpin = binding.getRoot().findViewById(R.id.inflatedShangpin);
            vpShangpin = inflatedShangpin.findViewById(R.id.vp_option1);
            tlTitleShangpin = inflatedShangpin.findViewById(R.id.tl_option1_title);
            tvTitleShangpin = inflatedShangpin.findViewById(R.id.tv_option1_title);
            // 商品材料
            if (vpShangpin != null && shangpinHomeMenuEntity != null) {
                updateRecommendCateViews(tlTitleShangpin, vpShangpin, tvTitleShangpin, shangpinHomeMenuEntity.getData(), shangpinHomeMenuEntity.getType(), false);
                showModuleViews();
            }
        }
    }

    @SuppressLint("AutoDispose")
    private void showModuleViews() {
        subscribe = Observable.interval(600, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(aLong -> {
                    i++;
                    switch (i) {
                        case 1:
                            vsZhaocai = binding.vsZhaocai.getViewStub();
                            vsZhaocai.inflate();
                            LinearLayout inflatedZhaocai = binding.getRoot().findViewById(R.id.inflatedZhaocai);
                            vpZhaocai = inflatedZhaocai.findViewById(R.id.vp_option2);
                            tlTitleZhaocai = inflatedZhaocai.findViewById(R.id.tl_option2_title);
                            tvTitleZhaocai = inflatedZhaocai.findViewById(R.id.tv_option2_title);
                            // 招采服务
                            if (vpZhaocai != null && zhaocaiHomeMenuEntity != null) {
                                updateRecommendCateViews(tlTitleZhaocai, vpZhaocai, tvTitleZhaocai, zhaocaiHomeMenuEntity.getData(), zhaocaiHomeMenuEntity.getType(), false);
                            }
                            break;
                        case 3:
                            vsJicai = binding.vsJicai.getViewStub();
                            vsJicai.inflate();
                            LinearLayout inflatedJicai = binding.getRoot().findViewById(R.id.inflatedJicai);
                            vpJicai = inflatedJicai.findViewById(R.id.vp_option3);
                            tlTitleJicai = inflatedJicai.findViewById(R.id.tl_option3_title);
                            tvTitleJicai = inflatedJicai.findViewById(R.id.tv_option3_title);
                            // 采集服务
                            if (vpJicai != null && jicaiHomeMenuEntity != null) {
                                updateRecommendCateViews(tlTitleJicai, vpJicai, tvTitleJicai, jicaiHomeMenuEntity.getData(), jicaiHomeMenuEntity.getType(), false);
                            }
                            break;
                        case 2:
                            vsZulin = binding.vsZulin.getViewStub();
                            vsZulin.inflate();
                            LinearLayout inflatedZulin = binding.getRoot().findViewById(R.id.inflatedZulin);
                            vpZulin = inflatedZulin.findViewById(R.id.vp_option4);
                            tlTitleZulin = inflatedZulin.findViewById(R.id.tl_option4_title);
                            tvTitleZulin = inflatedZulin.findViewById(R.id.tv_option4_title);
                            // 租赁服务
                            if (vpZulin != null && zulinHomeMenuEntity != null) {
                                updateRecommendCateViews(tlTitleZulin, vpZulin, tvTitleZulin, zulinHomeMenuEntity.getData(), zulinHomeMenuEntity.getType(), false);
                            }
                            break;
                        case 4:
                            vsGongdui = binding.vsGongdui.getViewStub();
                            vsGongdui.inflate();
                            LinearLayout inflatedGongdui = binding.getRoot().findViewById(R.id.inflatedGongdui);
                            vpGongdui = inflatedGongdui.findViewById(R.id.vp_option5);
                            tlTitleGongdui = inflatedGongdui.findViewById(R.id.tl_option5_title);
                            tvTitleGongdui = inflatedGongdui.findViewById(R.id.tv_option5_title);
                            // 工队
                            if (vpGongdui != null && gongduiHomeMenuEntity != null) {
                                updateRecommendCateViews(tlTitleGongdui, vpGongdui, tvTitleGongdui, gongduiHomeMenuEntity.getData(), gongduiHomeMenuEntity.getType(), false);
                            }
                            break;
                        case 5:
                            vsWuliu = binding.vsWuliu.getViewStub();
                            vsWuliu.inflate();
                            LinearLayout inflatedWuliu = binding.getRoot().findViewById(R.id.inflatedWuliu);
                            vpWuliu = inflatedWuliu.findViewById(R.id.vp_option6);
                            tlTitleWuliu = inflatedWuliu.findViewById(R.id.tl_option6_title);
                            tvTitleWuliu = inflatedWuliu.findViewById(R.id.tv_option6_title);
                            // 物流
                            if (vpWuliu != null && wuliuHomeMenuEntity != null) {
                                updateRecommendCateViews(tlTitleWuliu, vpWuliu, tvTitleWuliu, wuliuHomeMenuEntity.getData(), wuliuHomeMenuEntity.getType(), false);
                            }
                            break;
                        case 6:
                            vsQifu = binding.vsQifu.getViewStub();
                            vsQifu.inflate();
                            LinearLayout inflatedQifu = binding.getRoot().findViewById(R.id.inflatedQifu);
                            vpQifu = inflatedQifu.findViewById(R.id.vp_option8);
                            tlTitleQifu = inflatedQifu.findViewById(R.id.tl_option8_title);
                            tvTitleQifu = inflatedQifu.findViewById(R.id.tv_option8_title);
                            // 企业服务
                            if (vpQifu != null && qifuHomeMenuEntity != null) {
                                updateRecommendCateViews(tlTitleQifu, vpQifu, tvTitleQifu, qifuHomeMenuEntity.getData(), qifuHomeMenuEntity.getType(), false);
                            }
                            break;
                        case 7:
                            vsZhaoshang = binding.vsZhaoshang.getViewStub();
                            vsZhaoshang.inflate();
                            LinearLayout inflatedZhaoshang = binding.getRoot().findViewById(R.id.inflatedZhaoshang);
                            vpZhaoshang = inflatedZhaoshang.findViewById(R.id.vp_option9);
                            tlTitleZhaoshang = inflatedZhaoshang.findViewById(R.id.tl_option9_title);
                            tvTitleZhaoshang = inflatedZhaoshang.findViewById(R.id.tv_option9_title);
                            // 招商引资
                            if (vpZhaoshang != null && zhaoshangHomeMenuEntity != null) {
                                updateRecommendCateViews(tlTitleZhaoshang, vpZhaoshang, tvTitleZhaoshang, zhaoshangHomeMenuEntity.getData(), zhaoshangHomeMenuEntity.getType(), false);
                            }
                            break;
                        case 8:
                            vsQiye = binding.vsQiye.getViewStub();
                            vsQiye.inflate();
                            LinearLayout inflatedQiye = binding.getRoot().findViewById(R.id.inflatedQiye);
                            vpQiye = inflatedQiye.findViewById(R.id.vp_option7);
                            tlTitleQiye = inflatedQiye.findViewById(R.id.tl_option7_title);
                            tvTitleQiye = inflatedQiye.findViewById(R.id.tv_option7_title);
                            // 企业经营
                            if (vpQiye != null && qiyeHomeMenuEntity != null) {
                                updateRecommendCateViews(tlTitleQiye, vpQiye, tvTitleQiye, qiyeHomeMenuEntity.getData(), qiyeHomeMenuEntity.getType(), false);
                            }
                            break;
                        case 9:
                            renderComplete = true;
                            if (isChangeCity) {
                                refreshHomeData();
                            }
                            vsFenxiang = binding.vsFenxiang.getViewStub();
                            vsFenxiang.inflate();
                            LinearLayout inflatedFenxiang = binding.getRoot().findViewById(R.id.inflatedFenxiang);
                            vpFenxiang = inflatedFenxiang.findViewById(R.id.top_viewpager);
                            tlTitleFenxiang = inflatedFenxiang.findViewById(R.id.tab_layout_video);
                            tvTitleFenxiang = inflatedFenxiang.findViewById(R.id.tv_all);
                            // 分享
                            if (vpQiye != null) {
                                showVideoType(fenxiangList, "local");
                            }
                            subscribe.dispose();
                            break;
                    }

                });
    }

    // Header View
    private ProgressBar progressBar;
    private TextView textView;

    private View createHeaderView() {
        View headerView = LayoutInflater.from(binding.swipeRefresh.getContext())
                .inflate(R.layout.super_swipe_refresh_head, null);
        progressBar = headerView.findViewById(R.id.pb_view);
        textView = headerView.findViewById(R.id.text_view);
        textView.setText("下拉刷新");
        progressBar.setVisibility(View.GONE);
        return headerView;
    }

    @SuppressLint({"AutoDispose", "CheckResult"})
    private void init() {
        //商品三级分类的数据
        model.getCategoryModel();
        //banner数据
        model.getHomeMenuList(false);
        //全局省市区json数据
        model.getAddressModel();
        model.getPictureList(false);
        //获取首页企业推荐
        model.getCompanyTitleList("init");
        //获取大首页广告banner图集
        model.getHomeAdData(false);
        //首页各模块数据
        model.recomandCate(false);
        //视频分类
        model.videoTypeList(false);
        //商品材料
        model.getMenuModels("", false);
        //  在这里去处理你想延时加载的东西
        if (titleData == null) {
            //商品列表需要的数据
            model.firstRecommendMenu();
        }
        initLocation();
    }

    /**
     * 初始化首页企业推荐界面
     */
    public void initCompanyTitle(List<EnterpriseEditEntity> data) {
        if (binding == null) {
            return;
        }
        vsCompany = binding.vsCompany.getViewStub();
        if (vsCompany != null) {
            vsCompany.inflate();
        }
        if (vsCompany != null) {
            inflatedCompany = binding.getRoot().findViewById(R.id.inflatedCompany);
            bigHomeCompary = new BigHomeComparyWidget(this, inflatedCompany);
        }
        if (bigHomeCompary != null) {
            bigHomeCompary.unInit();
        }
        if (data == null || data.size() == 0) return;
        bigHomeCompary.initData(data);
        boolean isType = MkvUtils.get().getBoolean(MkvUtils.CommomData, CacheMarker.DisplaySettingsType, true);
        boolean isQY = MkvUtils.get().getBoolean(MkvUtils.CommomData, CacheMarker.DisplaySettingsQY, true);
        bigHomeCompary.setIsAotu(isType, isQY);
    }

    private void initLocation() {
        if (mapLocationTools == null) {
            mapLocationTools = new MapLocationTools(getContext());
        }
        mapLocationTools.initLocation(false);
        mapLocationTools.setLocationListener(new MapLocationTools.LocationListener() {
            @Override
            public void getLocationListener(String address, Double Longitude, Double Latitude) {
                SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LONGITUDE_ID, String.valueOf(Longitude));
                SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LATITUDE_ID, String.valueOf(Latitude));
            }
        });
        mapLocationTools.startLocation();
    }


    public void getPictureList(List<PictureEntity> data) {
        homePictureAdapter.setDatas(data);
    }


    private void homePictureItemClick(String name) {
        if (name.equals("租赁")) {
            //可视租赁
            initLeaseLoc();
        } else if (name.equals("商品")) {
            //可视商品
            SupplierActivity4.start(getActivity(), true, shopmenuList);
        } else if (name.equals("货车")) {//物流——可视找车
            GoodsCarsActivity.start(getActivity(), 1, true, false);
        } else if (name.equals("货源")) {//物流——可视找货
            GoodsCarsActivity.start(getActivity(), 0, false, false);
        } else if (name.equals("招采")) {//招采——招标大厅——右侧地图
            PickMapActivity.start(getActivity());
        } else if (name.equals("企业")) {//企业——地图查找
            EnterpriseAndMapActivity3.start(getActivity());
        } else if (name.equals("工队")) { //工队——地图查找
            FigureCheckActivity.start(getActivity());
        } else if (name.equals("货运")) { //货运大厅图查模式
            //GoodsCarsActivity.start(getActivity(), 0, false, false);
            LogisticsMapActivity.start(getActivity());
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_more:
                //工程材料
                EventBus.getDefault().postSticky(CategoryEvent.make(EventConstant.EVENT_CATEGORY_CHOOSE, 0));
                HomeCategoryActivity.start(getActivity());
                break;
            case R.id.et_view:
                SearchActivity3.start(getActivity(), 0);
                break;
            case R.id.iv_quick_entry:
                EventBus.getDefault().postSticky(new QuickEntryEvent(binding.ivQuickEntry, null));
                break;
        }
    }

    public void showBannerView(List<BannerEntity> bannerData) {
        binding.swipeRefresh.setRefreshing(false);
        ArrayList<String> imgs = new ArrayList<>();
        for (BannerEntity entity : bannerData) {
            imgs.add(entity.getImgUrl());
        }
    }

    public void closeRefresh() {
        binding.swipeRefresh.setRefreshing(false);
    }

    public void showMenuView(List<HomeManageMenuEntity> data) {
        //拆解接口列表更改为3个/1个集合列表
        List<List<HomeManageMenuEntity>> newData = getMenuList(data);
        binding.swipeRefresh.setRefreshing(false);
        HomeMenuAdapter adapter = new HomeMenuAdapter(getActivity(), newData);
        adapter.setListener(new HomeMenuAdapter.HomeMenuClickListener() {
            @Override
            public void onMenuClick(HomeManageMenuEntity entity) {
                onMenuItemClick(entity);
                useModeNumToService(entity.getName());
            }
        });
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        binding.recyclerMenu.setLayoutManager(manager);
        binding.recyclerMenu.setAdapter(adapter);
        binding.treeIndicator.bindRecyclerView(binding.recyclerMenu);
    }

    private List<List<HomeManageMenuEntity>> getMenuList(List<HomeManageMenuEntity> data) {
        List<List<HomeManageMenuEntity>> newData = new ArrayList<>();
        if (data == null) return newData;
        int index = (int) Math.ceil(data.size() / 3);
        for (int i = 0; i < index; i++) {
            List<HomeManageMenuEntity> entityList = new ArrayList<>();
            entityList.add(data.get(i));
            if (data.get(i + index) != null)
                entityList.add(data.get(i + index));
            if (data.get(i + 2 * index) != null)
                entityList.add(data.get(i + 2 * index));
            newData.add(entityList);
            continue;
        }
        return newData;
    }

    private void useModeNumToService(String titleName) {
        if (flowLogUtils == null) {
            flowLogUtils = new FlowLogUtils();
        }
        flowLogUtils.useModeNumToService(titleName);
    }

    private void onMenuItemClick(HomeManageMenuEntity entity) {
        String typeCode = entity.getCode();
        if (typeCode.equals("paimaishangji")){ //拍卖大厅
            AuctionHallActivity.start(getActivity(),"2");
        } else if (typeCode.equals("xiaoshoushangpin")) {
            //销售商品
            GoodsAggregateActivity.start(getActivity(), null, 0, "", null, null, false);
        } else if (typeCode.equals("ziyingxiaoshou")) {
            //自营商品
            GoodsAggregateActivity.start(getActivity(), null, 1, "", null, null, false);
        } else if (typeCode.equals("1455075302911901696")) {
            //企业查询
            initLoc(false);
        } else if (typeCode.equals("zhaobiaogonggao")) {
            //招标公告
          //  PickHallActivity3.start(getActivity(), 1);
            PickListActivity.start(getActivity(),"2",0);
        } else if (typeCode.equals("jingjiacaigou")) {
            //竞价采购
            PickBiddingListActivity.start(getActivity());
        } else if (typeCode.equals("gongrengongdui")) {
            //工人工队
            EventBus.getDefault().postSticky(CategoryEvent2.make(EventConstant.EVENT_CATEGORY_CHOOSE2, 5));
        } else if (typeCode.equals("xufangjicai")) {
            //需方集采
            XuFangFaQiActivity.start(getActivity(), "1");
        } else if (typeCode.equals("zhaoshangyinzi")) {
            //招商引资
            EventBus.getDefault().postSticky(CategoryEvent2.make(EventConstant.EVENT_CATEGORY_CHOOSE2, 27));
        } else if (typeCode.equals("yunshuzhaoche")) { //运输找车
            //货车大厅
            GoodsCarsActivity.start(getActivity(), 0, true);
        } else if (typeCode.equals("huoyunshangji")) {//货运商机
            //货运大厅
            GoodsCarsActivity.start(getActivity(), 0, false);
        } else if (typeCode.equals("jingjiazhaoche")) {
            //竞价找车
            GoodsCarsActivity.start(getActivity(), 1, true);
        } else if (typeCode.equals("chuzudating")) {
            //出租大厅
            LeaseHallActivity2.start(getActivity());
        } else if (typeCode.equals("qiuzushangji")) {
            //求租商机
            LeaseHallActivity2.start(getActivity(), 1, 0);
        } else if (typeCode.equals("ruanjianfuwu")) {
            //软件服务 1178
            ServiceTypeActivity.start(getActivity(), "1178", "软件服务");
        } else if (typeCode.equals("gongrenlaowu")) {
            //工人劳务
            ActivityJump.jumpToActivity(getContext(), LaborServiceAndEmploymentActivity.class);
        } else if (typeCode.equals("huiyuanjingying")) {
            //会员经营
            EventBus.getDefault().postSticky(CategoryEvent2.make(EventConstant.EVENT_CATEGORY_CHOOSE2, 24));
        } else if (typeCode.equals("jicaishangpin")) {
            //集采商品
            GoodsAggregateActivity.start(getActivity(), null, 2, "", null, null, false);
        } else if (typeCode.equals("cuxiaoshangpin")) {
            //促销商品
            GoodsAggregateActivity.start(getActivity(), null, 3, "", null, null, false);
        } else if (typeCode.equals("zhijiejingjia")) {
            //直接竞价
            PickBiddingListActivity.start(getActivity());
        } else if (typeCode.equals("zhaobiaoyugao")) {
            //招标预告
            PickNoticeActivity.start(getActivity()); //招标预公告
        } else if (typeCode.equals("xuqiuyugao")) {
            //需求预告
            DemandForecastActivity.start(getActivity());
        } else if (typeCode.equals("jicaizhuangxiang")) {
            //集采专项
            XuFangFaQiActivity.start(getActivity(), "2");
        } else if (typeCode.equals("weixiufuwu")) {
            //维修服务
            MToast.showToast(getActivity(), "功能开发中，敬请期待");
        } else if (typeCode.equals("gongchenggongsi")) {
            //工程公司 5
            //"用工需求","工人大厅","工队大厅","工种报价","工程分包","工程公司","人气工队"
            com.swgk.core.common.utils.ActivityJump.startActivity(PathTeam.PackersTabActivity,Pair.create("type",5));
        } else if (typeCode.equals("tongchengyonggong")) {
            //同城用工 0
            //"用工需求","工人大厅","工队大厅","工种报价","工程分包","工程公司","人气工队"
            com.swgk.core.common.utils.ActivityJump.startActivity(PathTeam.PackersTabActivity,Pair.create("type",0));
        } else if (typeCode.equals("gongchengfenbao")) {
            //工程分包 4
            //"用工需求","工人大厅","工队大厅","工种报价","工程分包","工程公司","人气工队"
            com.swgk.core.common.utils.ActivityJump.startActivity(PathTeam.PackersTabActivity,Pair.create("type",4));
        } else if (typeCode.equals("gongzhongbaojia")) {
            //工种报价 3
            //"用工需求","工人大厅","工队大厅","工种报价","工程分包","工程公司","人气工队"
            com.swgk.core.common.utils.ActivityJump.startActivity(PathTeam.PackersTabActivity,Pair.create("type",3));
        } else if (typeCode.equals("huiyuanguanli")) {
            //会员管理
            if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                //跳入登录界面验证
                VerificationCodeLoginActivity.start(getActivity());
            } else {
                MemberManageActivity.start(getActivity());
            }
        } else if (typeCode.equals("rexiaoshangpin")) {
            //热销商品
            GoodsAggregateActivity.start(getActivity(), null, 4, "", null, null, false);
        } else if (typeCode.equals("guanggaoxuanchuan")) {
            //广告宣传 1152
            ServiceTypeActivity.start(getActivity(), "1152", "广告宣传");
        } else if (typeCode.equals("zhongbiaogonggao")) {
            //中标公告
            PickWinningNoticeActivity.start(getActivity());
        } else if (typeCode.equals("youpinxiaoshou")) {
            //油品销售
            MToast.showToast(getActivity(), "功能开发中，敬请期待");
        } else if (typeCode.equals("baoxianfuwu")) {
            //保险服务
            ServiceTypeActivity.start(getActivity(), "1240", "保险服务");
        } else if (typeCode.equals("wodeguanzhu")) {
            //我的关注
            if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                //跳入登录界面验证
                VerificationCodeLoginActivity.start(getActivity());
            } else {
                if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0) == 0) {
                    if (!SharedPreferenceUtil.getInstance().getSaveBooleanData(SharedPreferenceUtil.PERSON_AUTH, false)) {
                        ACAdminDialogUtils.showACDialog(ACAdminDialogUtils.TYPE_AUTH_NO_AC, getActivity());
                        return;
                    }
                    IntelligentAttentionActivity.start(getActivity());
                } else {
                    MToast.showToast(getActivity(), "请切换至个人身份");
                }
            }
        } else if (typeCode.equals("zhishichanquan")) {
            //知识产权
            IPActivity.startAction(getActivity());
        } else if (typeCode.equals("ershouzhuanrang")) {
            //二手转让
            ActivityJump.jumpToActivity(getActivity(), MakeOverActivity.class);
        } else if (typeCode.equals("zhishifenxiang")) {
            //知识分享
            SharePermissionUtils.getPermission(getActivity());
        } else {
            SharedPreferenceUtil.init(getActivity());
            if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                //跳入登录界面验证
                VerificationCodeLoginActivity.start(getActivity());
            } else {
                checkPublishData(entity.getName());
            }
                        /*else if (entity.getName().equals("询价发布")) {
                             //询价发布
                        } else if (entity.getName().equals("商品发布")) {
                            //商品发布
                        } else if (entity.getName().equals("机械发布")) {
                            //机械发布
                        } else if (entity.getName().equals("设备发布")) {
                            //设备发布
                        } else if (entity.getName().equals("车辆发布")) {
                            //车辆发布
                        } else if (entity.getName().equals("工队发布")) {
                            //工队发布
                        } else if (entity.getName().equals("货源发布")) {
                            //货源发布
                        } else if (entity.getName().equals("承运发布")) {
                            //承运发布
                        }*/
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(ChooseAreaEvent event) {
        //暂时展示全国数据，不需要根据定位刷新数据
       /* if (event.getMessageTag() == EventConstant.EVENT_CHOOSE_AERA) {
            ProvinceEntity<List<ProvinceEntity>> list = (ProvinceEntity<List<ProvinceEntity>>) event.getMessageData();
            menuAdapter = null;
            if (!init) {
                model.recomandCate(MATERIAL);
                model.recomandCate(RECRUIT);
                model.recomandCate(RENT);
                model.recomandCate(TEAM);
                model.recomandCate(LOGISTICS);
                model.recomandCate(COLLEGE);
                model.recomandCate(GROUPBUY);
                //底部view pager
                EventBus.getDefault().postSticky(MenuEvent.make().setMessageTag(EventConstant.EVENT_BIG_HOME_RE).setNo(titles[select]));
            }
//            model.getMenuModel(list.getId() + "");
//            model.recommendMenu(list.getId() + "");
        }*/
    }

    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    private String isEnterpriseAuth = "";
    private String isDriverAuth = "";
    //    private boolean isPersonAuth = false;
    private String RELEVANCE = "";
    private boolean IS_GOODS_PUBLISH = false;

    public void checkPublishData(String id) {
        SharedPreferenceUtil.init(getActivity());
        isEnterpriseAuth = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.ENTERPRISE_AUTH, "");
        isDriverAuth = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.DRIVER_AUTH, "");
        isPersonAuth = SharedPreferenceUtil.getInstance().getSaveBooleanData(SharedPreferenceUtil.PERSON_AUTH, false);
        RELEVANCE = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.RELEVANCE, "");
        IS_GOODS_PUBLISH = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.CHILD_MENU, "").contains(ACAdminDialogUtils.MK_ADDCOMMODITY);
        showLogMsg(id);
    }

    private void showLogMsg(String id) {
        //企业认证状态四种(NONE,STANDBY,FAIL,SUCCESS)
        if ("商品发布".equals(id) || "询价发布".equals(id)) {
            if (!isPersonAuth) {
                showDialog2(id, "暂无权限，请进行实名认证？");
            } else if ("SUCCESS".equals(isEnterpriseAuth) || ("1".equals(RELEVANCE) && IS_GOODS_PUBLISH)) {
                //已认证或者是关联企业有权限
                isAuth(id);
            } else if ("1".equals(RELEVANCE)) {
                //未认证且是关联企业无权限
                isAuth(id);
            } else {
                // 未认证且未关联企业无权限
                showDialog2(id, "暂无权限，请进行企业认证？");
            }
            return;
        }
        if ("机械发布".equals(id) || "设备发布".equals(id) || "车辆发布".equals(id) || "工队发布".equals(id) || "分享制作".equals(id)) {
            if (!isPersonAuth) {
                showDialog2(id, "暂无权限，请进行实名认证？");
            } else {
                isAuth(id);
            }
            return;
        }
        if ("承运发布".equals(id)) {
            if (!"SUCCESS".equals(isDriverAuth)) {
                showDialog2(id, "暂无权限，请进行司机认证？");
            } else {
                isAuth(id);
            }
            return;
        }
        if ("货源发布".equals(id)) {
            if ("SUCCESS".equals(isEnterpriseAuth) || ("1".equals(RELEVANCE) && IS_GOODS_PUBLISH)) {
                //已认证或者是关联企业有权限
                isAuth(id);
            } else if ("1".equals(RELEVANCE)) {
                //未认证且是关联企业无权限
                isAuth(id);
            } else {
                showDialog2(id, "暂无权限，请进行企业认证？");
            }
        }
    }

    private void isAuth(String id) {
        if (isPersonAuth) {
            if ("SUCCESS".equals(isEnterpriseAuth)) {
                if (id.equals("注册")) {
                    //注册
                    EventBus.getDefault().postSticky(MenuEvent.make().setMessageTag(EventConstant.EVENT_BIG_HOME_JUMP_CENTER));
                } else if (id.equals("询价发布")) {
                    //询价发布
                    Intent createGood = new Intent(getActivity(), NewPurchasesActivity.class);
                    createGood.putExtra("GOOD_EDIT", false);
                    createGood.putExtra("GOOD_ADD", false);
                    createGood.putExtra("GOOD_ENTITY", new GoodsItemEntity());
                    getActivity().startActivity(createGood);
                } else if (id.equals("商品发布")) {
                    //商品发布
                    GoodsPublishActivity.start(getActivity());
                } else if (id.equals("机械发布")) {
                    //机械发布
                    LeaseMachineActivity.start(getActivity());//2021年2月2日改成发布页
//                    MachineListActivity.start(getActivity());//8月大首页改成列表页
                } else if (id.equals("设备发布")) {
                    //设备发布
                    DevicePublishActivity.start(getActivity());//9月18日改成发布页
//                    DeviceListActivity.start(getActivity());//8月大首页改成列表页
                } else if (id.equals("车辆发布")) {
                    //车辆发布
                    CarPublishActivity1.start(getActivity());
                } else if (id.equals("工队发布")) {
                    //工队发布
                    PackersPublishActivity.start(getActivity());
                } else if (id.equals("货运发布")) {
                    //货运发布
                } else if (id.equals("订单管理")) {
                    //订单管理
                } else if (id.equals("货源发布")) {
                    //货源发布
                    PublishCargoActivity.start(getActivity());
                } else if (id.equals("承运发布")) {
                    //承运发布
               /*     if ("SUCCESS".equals(isDriverAuth)) {*/
                        ARouter.getInstance().build(PathLogistics.CarriagePushActivity).navigation();
                    /*} else {
                        Intent intent = new Intent(getActivity(), AddDriverInfoActivity.class);
                        getActivity().startActivity(intent);
                    }*/
                } else if (id.equals("分享制作")) {
                    //分享制作
                    ShareRecoedVideoActivity.start(getActivity(), "BIG_HOME");
                }
            } else {
                if (id.equals("机械发布")) {
                    //机械发布
                    LeaseMachineActivity.start(getActivity());//2021年2月2日改成发布页
                } else if (id.equals("商品发布")) {
                    if (("1".equals(RELEVANCE) && IS_GOODS_PUBLISH)) {
                        //商品发布
                        GoodsPublishActivity.start(getActivity());
                    } else {
                        Toast.makeText(getActivity(), "暂无权限，请联系管理员", Toast.LENGTH_SHORT).show();
                    }
                } else if (id.equals("设备发布")) {
                    //设备发布
                    DevicePublishActivity.start(getActivity());
//                    DeviceListActivity.start(getActivity());
                } else if (id.equals("车辆发布")) {
                    //车辆发布
                    CarPublishActivity1.start(getActivity());
                } else if (id.equals("工队发布")) {
                    //工队发布
                    PackersPublishActivity.start(getActivity());
                } else if (id.equals("货运发布")) {
                    //货运发布
                } else if (id.equals("订单管理")) {
                    //订单管理
                } else if (id.equals("承运发布")) {
                    //承运发布
                  /*  if ("SUCCESS".equals(isDriverAuth)) {*/
                        ARouter.getInstance().build(PathLogistics.CarriagePushActivity).navigation();
                  /*  } else {
                        Intent intent = new Intent(getActivity(), AddDriverInfoActivity.class);
                        getActivity().startActivity(intent);
                    }*/
                }
                /*else if (id.equals("货源发布")) {
                    //货源发布
                    CarrierBargainingActivity.start(getActivity());
                }*/
                else {
                    AuthActivity3.start(getActivity());
                }
            }
        } else {
            AuthActivity3.start(getActivity());
        }
    }

    //弹框跳转认证
    public void showDialog2(String id, String msg) {
        View view = View.inflate(getActivity(), R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        TextView tv_message = (TextView) view.findViewById(R.id.tv_message);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("温馨提示");
        TextView tv_logout_confirm = (TextView) view.findViewById(R.id.tv_logout_confirm);
        tv_logout_confirm.setText("确定");
        TextView tv_logout_cancel = (TextView) view.findViewById(R.id.tv_logout_cancel);
        tv_message.setText(msg);

        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isAuth(id);
                roundCornerDialog.dismiss();
            }
        });

        //取消
        tv_logout_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }

    private void showDialog() {
        View view = View.inflate(getActivity(), R.layout.dialog_map_window, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        //roundCornerDialog.setOnKeyListener(keylistener);//设置点击返回键Dialog不消失

        ImageView img_close = view.findViewById(R.id.img_close);
        TextView tv_look = view.findViewById(R.id.tv_look);

        //关闭
        img_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //请求接口
                roundCornerDialog.dismiss();
            }
        });
        //查看详情
        tv_look.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                ShopInfoActivity.start(getActivity(), bossEntity.getId());
            }
        });
    }

    public void showCategoryView(List<MenuEntity<MenuEntity<MenuEntity>>> menuEntityList) {
        this.mMaterialData = menuEntityList;
    }

    //首次预请求商品所需数据
    public void setRecommendMenuData(List<MenuEntity> datas) {
        this.titleData = datas;
    }

    public void showVideoType(List<MenuEntity> list, String from) {
        if (list != null && list.size() > 0 && from.equals("net")) {
            fenxiangList.clear();
            fenxiangList.addAll(list);
        }
        if (fenxiangList.size() == 0 || vpFenxiang == null) {
            return;
        }
        tlTitleFenxiang.clearOnTabSelectedListeners();
        //fenxiangList.get(0).setName("分享");
        fenxiangList.remove(0);
        if (fragmentVideoList == null) {
            fragmentVideoList = new ArrayList<>();
        }
        fragmentVideoList.clear();
        vpFenxiang.setVisibility(View.VISIBLE);
        for (int i = 0; i < fenxiangList.size(); i++) {
            fragmentVideoList.add(BigHomeVideoFragment.newInstance(fenxiangList.get(i).getName(), fenxiangList.get(i).getId()));
        }
        if (fragmentVideoList.size() == fenxiangList.size()){
            pagerAdapter2 = new CommPagerAdapter2(getChildFragmentManager(), fragmentVideoList, fenxiangList);
            vpFenxiang.setAdapter(pagerAdapter2);
        }else {
            //视频分类
            model.videoTypeList(true);
        }
        tlTitleFenxiang.setupWithViewPager(vpFenxiang);
        vpFenxiang.setCurrentItem(0);
        vpFenxiang.setOffscreenPageLimit(1);
        for (int i = 0; i < fenxiangList.size(); i++) {
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_tab_view_menu, null, false);
            tlTitleFenxiang.getTabAt(i).setCustomView(view);
            TextView tv = tlTitleFenxiang.getTabAt(i).getCustomView().findViewById(R.id.tv_tabItem);
            tv.setText(fenxiangList.get(i).getName());
            if (i == 0) {
                tv.setSelected(true);
            }
        }
        tlTitleFenxiang.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                TextView tv = tab.getCustomView().findViewById(R.id.tv_tabItem);
                tv.setSelected(true);
                tv.invalidate();
                if (tab.getPosition() != 0) {
                    tvTitleFenxiang.setTextColor(getActivity().getResources().getColor(R.color.color_tab_one));
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                TextView tv = tab.getCustomView().findViewById(R.id.tv_tabItem);
                tv.setSelected(false);
                tv.invalidate();
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @SuppressLint({"AutoDispose", "CheckResult"})
    public void showRecommendCate(List<HomeMenuEntity> data, boolean isRefresh) {
        if (!isRefresh) {
            bigHomeFragment.clear();
        }
        for (int i = 0; i < data.size(); i++) {
            HomeMenuEntity homeMenuEntity = data.get(i);
            switch (homeMenuEntity.getType()) {
                case BigHomeFragment3.MATERIAL:
//                    mMaterialData.addAll(homeMenuEntity.getData().getTagList().get(0).getChildList());
                    if (isRefresh) {
                        setRefreshChildFragment(vpShangpin, i, isRefresh);
                    } else {
                        shangpinHomeMenuEntity = homeMenuEntity;
                        // 商品/材料
                        if (vpShangpin != null) {
                            updateRecommendCateViews(tlTitleShangpin, vpShangpin, tvTitleShangpin, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }
                    }
                    break;
                case BigHomeFragment3.RECRUIT:
                    if (isRefresh) {
                        setRefreshChildFragment(vpZhaocai, i, isRefresh);
                    } else {
                        zhaocaiHomeMenuEntity = homeMenuEntity;
                        // 招标/竞价
                        if (vpZhaocai != null) {
                            updateRecommendCateViews(tlTitleZhaocai, vpZhaocai, tvTitleZhaocai, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }
                    }
                    break;
                case BigHomeFragment3.GROUPBUY:
                    if (isRefresh) {
                        setRefreshChildFragment(vpJicai, i, isRefresh);
                    } else {
                        jicaiHomeMenuEntity = homeMenuEntity;
                        // 采集服务
                        if (vpJicai != null) {
                            updateRecommendCateViews(tlTitleJicai, vpJicai, tvTitleJicai, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }

                    }
                    break;
                case BigHomeFragment3.RENT:
                    if (isRefresh) {
                        setRefreshChildFragment(vpZulin, i, isRefresh);
                    } else {
                        zulinHomeMenuEntity = homeMenuEntity;
                        // 租赁市场
                        if (vpZulin != null) {
                            updateRecommendCateViews(tlTitleZulin, vpZulin, tvTitleZulin, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }
                    }
                    break;
                case BigHomeFragment3.TEAM:
                    if (isRefresh) {
                        setRefreshChildFragment(vpGongdui, i, isRefresh);
                    } else {
                        gongduiHomeMenuEntity = homeMenuEntity;
                        // 工队服务
                        if (vpGongdui != null) {
                            updateRecommendCateViews(tlTitleGongdui, vpGongdui, tvTitleGongdui, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }
                    }
                    break;
                case BigHomeFragment3.LOGISTICS:
                    if (isRefresh) {
                        setRefreshChildFragment(vpWuliu, i, isRefresh);
                    } else {
                        wuliuHomeMenuEntity = homeMenuEntity;
                        // 物流货运
                        if (vpWuliu != null) {
                            updateRecommendCateViews(tlTitleWuliu, vpWuliu, tvTitleWuliu, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }

                    }
                    break;
                case BigHomeFragment3.OPERATION:
                    if (isRefresh) {
                        setRefreshChildFragment(vpQiye, i, isRefresh);
                    } else {
                        qiyeHomeMenuEntity = homeMenuEntity;
                        // 企业推荐
                        if (vpQiye != null) {
                            updateRecommendCateViews(tlTitleQiye, vpQiye, tvTitleQiye, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }
                    }
                    break;
                case BigHomeFragment3.SERVICES:
                    if (isRefresh) {
                        setRefreshChildFragment(vpQifu, i, isRefresh);
                    } else {
                        qifuHomeMenuEntity = homeMenuEntity;
                        // 企业服务
                        if (vpQifu != null) {
                            updateRecommendCateViews(tlTitleQifu, vpQifu, tvTitleQifu, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }
                    }
                    break;
                case BigHomeFragment3.MERCHANTS:
                    if (isRefresh) {
                        setRefreshChildFragment(vpZhaoshang, i, isRefresh);
                    } else {
                        zhaoshangHomeMenuEntity = homeMenuEntity;
                        // 招商引资
                        if (vpZhaoshang != null) {
                            updateRecommendCateViews(tlTitleZhaoshang, vpZhaoshang, tvTitleZhaoshang, homeMenuEntity.getData(), homeMenuEntity.getType(), isRefresh);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        if (isRefresh) return;
        Observable.timer(600, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(aLong -> {
                    showShangpinView();
                });
    }

    private void updateRecommendCateViews(TabLayout tabLayout, ViewPager vp, TextView textView, HomeMenuEntity.DataBean data, String code, boolean isRefresh) {
        if (data != null) {
            bannerList = data.getBannerList();
        }
        tabLayout.clearOnTabSelectedListeners();
        List<Fragment> optionFragments = new ArrayList<>();
        if (bannerList != null) {
            switch (code) {
                case BigHomeFragment3.MATERIAL:
                    // 商品/材料
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(CommodityMaterialFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                case BigHomeFragment3.RECRUIT:
                    // 招标/竞价--招采
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(BiddingSignUpFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                case BigHomeFragment3.GROUPBUY:
                    // 采集服务
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(CentralizedMiningFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                case BigHomeFragment3.RENT:
                    // 租赁市场
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(LeasingMachineryFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                case BigHomeFragment3.TEAM:
                    // 工队服务
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(EngineeringTeamJobHuntingFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                case BigHomeFragment3.LOGISTICS:
                    // 物流货运
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(LogisticsAcceptForCarriageFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                case BigHomeFragment3.OPERATION:
                    // 企业经营
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(EnterpriseOperationFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                case BigHomeFragment3.SERVICES:
                    // 企业服务
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(CorporateServicesFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                case BigHomeFragment3.MERCHANTS:
                    // 招商引资
                    for (int i = 0; i < bannerList.size(); i++) {
                        optionFragments.add(MerchantsFragment.newInstance(i, bannerList.get(i), isRefresh));
                    }
                    break;
                default:
                    break;
            }
            bigHomeFragment.add(optionFragments);
        }
        if (data != null && isAdded()) {
            vp.setAdapter(new RecommendFragmentPagerAdapter(getChildFragmentManager(), optionFragments, data.getBannerList(), code));
        }
        if (vp instanceof HeightViewPager) {
            ((HeightViewPager) vp).resetHeight(0);
        }
        vp.setOffscreenPageLimit(1);
        tabLayout.setupWithViewPager(vp);
        View view;
        for (int i = 0; i < bannerList.size(); i++) {
            view = LayoutInflater.from(requireActivity()).inflate(R.layout.item_tab_view_menu, null, false);
            tabLayout.getTabAt(i).setCustomView(view);
            TextView tv = tabLayout.getTabAt(i).getCustomView().findViewById(R.id.tv_tabItem);
            tv.setText(bannerList.get(i).getName());
            if (i == 0) {
                tv.setSelected(true);
            }
        }
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                TextView tv = tab.getCustomView().findViewById(R.id.tv_tabItem);
                tv.setSelected(true);
                tv.invalidate();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                TextView tv = tab.getCustomView().findViewById(R.id.tv_tabItem);
                tv.setSelected(false);
                tv.invalidate();
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        if (data != null) {
            textView.setText(data.getTagList().get(0).getName());
        }
    }

    /**
     * 当手动执行下拉刷新时，需要刷新当前选中的子Fragment的列表数据
     *
     * @param vp        当前模块承载的VP
     * @param pos       当前需要刷新的模块
     * @param isRefresh 是否刷新 true为刷新，否则不是刷新
     */
    public void setRefreshChildFragment(HeightViewPager vp, int pos, boolean isRefresh) {
        //取出当前Vp选中的那个Tap项
        if (vp == null) {
            return;
        }
        int inxid = vp.getCurrentItem();
        if (bigHomeFragment.size() > pos) {
            //得到当前选中的Tab项对应的
            Fragment fm = bigHomeFragment.get(pos).get(inxid);
            ((BaseHeightViewPagerFragment) fm).IsRefresh(isRefresh);
        }
    }

    //商品二级分类
    public void showshopMenuView(List<MenuEntity> data) {
        shopmenuList.clear();
        if (data.get(0).getName().equals("全部")) {
            data.remove(0);
        }
        shopmenuList.addAll(data);
    }

    class RecommendFragmentPagerAdapter extends FragmentPagerAdapter {

        private List<Fragment> mFragments;
        private List<BannerEntity> mBannerEntities;
        private String code;

        public RecommendFragmentPagerAdapter(FragmentManager fm, List<Fragment> data, List<BannerEntity> bannerEntities, String code) {
            super(fm);
            this.code = code;
            mFragments = data;
            mBannerEntities = bannerEntities;
        }

        @Override
        public Fragment getItem(int position) {
            HeightViewPager heightViewPager = null;
            switch (code) {
                case BigHomeFragment3.MATERIAL:
                    // 商品
                    heightViewPager = vpShangpin;
                    break;
                case BigHomeFragment3.RECRUIT:
                    // 招采
                    heightViewPager = vpZhaocai;
                    break;
                case BigHomeFragment3.GROUPBUY:
                    // 采集服务
                    heightViewPager = vpJicai;
                    break;
                case BigHomeFragment3.RENT:
                    // 租赁市场
                    heightViewPager = vpZulin;
                    break;
                case BigHomeFragment3.TEAM:
                    //工队服务
                    heightViewPager = vpGongdui;
                    break;
                case BigHomeFragment3.LOGISTICS:
                    //物流货运
                    heightViewPager = vpWuliu;
                    break;
                case BigHomeFragment3.OPERATION:
                    //企业经营
                    heightViewPager = vpQiye;
                    break;
                case BigHomeFragment3.SERVICES:
                    //企业服务
                    heightViewPager = vpQifu;
                    break;
                case BigHomeFragment3.MERCHANTS:
                    //招商引资
                    heightViewPager = vpZhaoshang;
                    break;
            }
            BaseHeightViewPagerFragment fragment = (BaseHeightViewPagerFragment) mFragments.get(position);
            fragment.setHeightViewPager(heightViewPager);
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments == null ? 0 : mFragments.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return mBannerEntities.get(position).getName();
        }

        //禁止主动销毁已创建的页面
//        @Override
//        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
//            //super.destroyItem(container, position, object);
//        }
    }

    /**
     * 定位方法
     */
    private void initLoc(boolean isMap) {
        final String[] longitude = {SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "")};
        final String[] latitude = {SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "")};
        if (TextUtils.isEmpty(longitude[0]) || "0.0".equals(longitude[0])) {
            if (mapLocationTools == null) {
                mapLocationTools = new MapLocationTools(getContext());
            }
            mapLocationTools.initLocation(false);
            mapLocationTools.setLocationListener(new MapLocationTools.LocationListener() {
                @Override
                public void getLocationListener(String address, Double Longitude, Double Latitude) {
                    SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LONGITUDE_ID, String.valueOf(Longitude));
                    SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LATITUDE_ID, String.valueOf(Latitude));
                    longitude[0] = String.valueOf(Longitude);
                    latitude[0] = String.valueOf(Latitude);
                    TheEnterpriseOfActivity.start(getActivity(), longitude[0], latitude[0], isMap);
                }
            });
            mapLocationTools.startLocation();
        } else {
            EnterpriseAndMapActivity.start(getActivity(), longitude[0], latitude[0], isMap);
        }
    }

    /**
     * 获取定位信息跳租赁图查模块
     */
    private void initLeaseLoc() {
        if (mapLocationTools == null) {
            mapLocationTools = new MapLocationTools(getContext());
        }
        mapLocationTools.initLocation(false);
        mapLocationTools.setLocationListener(new MapLocationTools.LocationListener() {
            @Override
            public void getLocationListener(String address, Double Longitude, Double Latitude) {
                Bundle bundle = new Bundle();
                bundle.putString("title", address);
                bundle.putString("text", address);
                bundle.putDouble("lat", Latitude);
                bundle.putDouble("lon", Longitude);
                LeaseHallMapActivity.startForBundle(getActivity(), bundle);
            }
        });
        mapLocationTools.startLocation();
    }

    /*  */

    /*
     * 切换城市后刷新列表数据
     */
    public void refreshHomeData() {
        isChangeCity = true;
        if (!renderComplete) {
            return;
        }
        //banner数据
        model.getHomeMenuList(true);
        //视频分类
        model.videoTypeList(true);
        //获取大首页广告banner图集
        model.getHomeAdData(true);
        //材料
        model.recomandCate(true);
        //商品突查tab
        model.getMenuModels("", true);

        //获取首页企业推荐
        model.getCompanyTitleList("refreshHomeData");
    }
    /*
     * 大首页广告Banner图
     * */
    public void showAdType(HomeAdEntity entity) {
        setHomeAdBannerData(binding.homeBanner, entity.get_$1());
        setHomeAdBannerData(binding.homeCollectBanner, entity.get_$2());
        setHomeAdBannerData(binding.homeCompanyBanner, entity.get_$7());
        setHomeAdBannerData(binding.homeLeaseBanner, entity.get_$3());
        setHomeAdBannerData(binding.homeLogisticsBanner, entity.get_$5());
        setHomeAdBannerData(binding.homeMerchantsBanner, entity.get_$6());
        setHomeAdBannerData(binding.homePackersBanner, entity.get_$4());
        setHomeAdBannerData(binding.homeShareBanner, entity.get_$9());
        setHomeAdBannerData(binding.homeCompanyServiceBanner, entity.get_$8());
    }

    private void setHomeAdBannerData(XBanner homeBanner, List<HomeAdEntity.HomeAdBean> adBeanList) {
        homeBanner.setBannerData(adBeanList);
        homeBanner.loadImage(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                RequestOptions options = new RequestOptions();
                options.transform(new RoundedCorners(20));
                requestManager.load(adBeanList.get(position).getXBannerUrl()).apply(options).into((ImageView) view);
                ((ImageView) view).setScaleType(ImageView.ScaleType.FIT_XY);
            }
        });
    }

    /**
     * 用户切换身份后通知大首页刷新数据
     *
     * @param event
     */
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(RefreshHomeNoticeEVent event) {
        if (event.getMsgNoticeTag() == EventConstant.EVENT_NOTICE_REFRESH_HOME) {
            //获取首页企业推荐
            model.getCompanyTitleList("EventConstant.EVENT_NOTICE_REFRESH_HOME");
        }
        EventBus.getDefault().removeStickyEvent(event);
    }
}
